<template>
	<view class="page">
		<view style="font-size: 24rpx; margin: 20rpx;">共<text style="color:#257CFF">{{list.length}}</text>条数据</view>
		<!-- <u-loadmore fontSize="24rpx" loadmoreText="微卡" color="#000000" lineColor="#bfbfbf" line /> -->
		<view class="content" v-for="(item,index) in list" :key="index">
			<view class="order">
				<image class="img" :src="item.carImg"
					@click="$goBack(2,'/bundle/pages/vehicledetails/vehicledetails?id='+item.id)"></image>
				<view class="content1" @click="$goBack(2,'/bundle/pages/vehicledetails/vehicledetails?id='+item.id)">
					<view class="content-name">{{item.carName}}</view>
					<view class="content-map">{{item.carEndurance}}</view>
					<view class="content-map">电量:{{item.carElectricity}}</view>
					<view class="content-ma">售价：<text>{{item.carPrice}}</text>万</view>
				</view>
				<u-button @click="show=true,model1.reservationOrder.id=item.id"
					customStyle="margin-top: 80rpx;width:150rpx;height:70rpx;color:#000;font-size:28rpx;font-weight: 600;"
					color="#FBCC32">询底价</u-button>
			</view>
		</view>

	<u-toast ref="uToast"></u-toast>
		<u-popup :show="show" mode="center"  :round="10">
			<view style="text-align: center; font-size:34rpx ; margin: 10rpx;">请输入您的电话号码和姓名</view>
			<view style="text-align: center; font-size:24rpx ; margin: 10rpx;">*方便业务人员和你联系*</view>
			<view style="padding: 30rpx">
				<u--form labelPosition="left" :model="model1" :rules="rules" ref="uForm">
					<u-form-item label="姓名" prop="reservationOrder.userName" borderBottom ref="item1">
						<u--input v-model="model1.reservationOrder.userName" border="none"></u--input>
					</u-form-item>
					<u-form-item label="电话" prop="reservationOrder.userPhone" borderBottom ref="item1">
						<u--input v-model="model1.reservationOrder.userPhone" border="none"></u--input>
					</u-form-item>
				</u--form>
			</view>
				
			<view style="display: flex;">
				<u-button  type="primary" @click="submit">确定提交</u-button>
				<u-button @click="show=false">取消</u-button>
			</view>
		</u-popup>
	</view>
</template>

<script>
	import {
		apigetByBrandId,
		apisubmit
	} from '@/api/car.js'
	export default {
		data() {
			return {
				list: [],
				model1: {
					reservationOrder: {
						userName: '',
						userPhone: '',
						id:''
					},
				},
				rules: {
					'reservationOrder.userName': {
						type: 'string',
						required: true,
						message: '请填写姓名',
						trigger: ['blur', 'change']
					},
					'reservationOrder.userPhone': {
						type: 'string',
						required: true,
						message: '请填写电话',
						trigger: ['blur', 'change']
					},
				},
				ids: '',
				id: "",
				show: false
			}
		},
		onReady() {
			//如果需要兼容微信小程序，并且校验规则中含有方法等，只能通过setRules方法设置规则。
			this.$refs.uForm.setRules(this.rules)
		},
		onLoad(e) {
			this.id = e.id
			this.getByBrandId()
		},
		methods: {
			submit() {
				this.$refs.uForm.validate().then(res => {
					uni.$u.toast('校验通过')
					apisubmit(this.model1).then((res)=>{
						if(res.code==200){
							this.$refs.uToast.show({
								type: 'default',
								message: "提交成功"
							})
						}
					})
					
				}).catch(errors => {
					uni.$u.toast('校验失败')
				})
			},
			getByBrandId() {
				apigetByBrandId(this.id).then((res) => {
					this.list = res.data
				})
			}

		}
	}
</script>

<style lang="scss" scoped>
	.content {
		width: 718rpx;
		height: 210rpx;
		margin: 16rpx;
		padding: 10rpx 20rpx;
		box-sizing: border-box;
		background-color: #fff;
		border-radius: 20rpx;

		.order {
			margin: 20rpx 10rpx;
			display: flex;

			.img {
				border-radius: 10rpx;
				width: 140rpx;
				height: 140rpx;
			}

			.content1 {
				width: 340rpx;
				margin-left: 20rpx;
				line-height: 40rpx;

				.content-name {
					font-size: 28rpx;
					font-weight: 600;
				}

				.content-map {
					font-size: 24rpx;
					// color:#949494 ;
				}

				.content-ma {
					font-size: 24rpx;

					text {
						font-size: 32rpx;
						color: #FF0000;
						font-weight: 600;
					}
				}
			}
		}

		.store {
			font-size: 26rpx;
			margin: 8rpx 0rpx;
		}

		.order-content {
			width: 666rpx;
			font-size: 24rpx;
			color: #666666;
			margin-bottom: 6rpx;
		}

		.time {
			margin-bottom: 8rpx;
			color: #949494;
			font-size: 24rpx;
		}

		.but {
			margin-top: 16rpx;
			font-size: 28rpx;

			@include flex(row, space-between, center) .button {
				color: #257CFF;
			}
		}
	}

	::v-deep .u-transition {
		// position: absolute !important; 
		top: 120rpx !important;
	}

	::v-deep .u-input {
		margin: 0rpx 40rpx 0rpx 32rpx;
		background-color: #efefef !important;

	}
</style>